<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>lesson 19</title>
    <script src="../dist/vue.js"></script>
  </head>
  <body>
    <div id="root"></div>
  </body>
  <script>
    // 动态组件: 根据数据的变化，结合 compoent 这个标签，来随时动态切换组件的现实
    // 异步组件: 是异步执行某些组件的逻辑，这叫做异步组件

    const listReactiveEffect = () => {
      const { reactive } = Vue;
      const list = reactive([]);
      const addToList = item => {
        list.push(item);
        console.log(item);
      };
      return { list, addToList };
    };

    const inputValEffect = () => {
      const { ref } = Vue;
      const inputVal = ref("");
      return { inputVal };
    };

    const app = Vue.createApp({
      template: `
          <div>
            <div>
              <input placeholder="请输入内容" v-model='inputVal'/>
              <button @click='() => addToList(inputVal)'>添加</button>
              <ul>
                <li v-for='item in list'>{{ item }}</li>
              </ul>
            </div>
          </div>
        `,
      setup(props, context) {
        const { list, addToList } = listReactiveEffect();
        const { inputVal } = inputValEffect();
        return { list, addToList, inputVal };
      }
    });

    app.component("child", {
      template: `
        <div>child</div>
      `,
      setup(props, context) {
        console.table({ props, context });
        return {};
      }
    });
    const vm = app.mount("#root");
  </script>
</html>
